
// XXX this is where WARP gets inserted

const xpcom = require("xpcom");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function WidgetURIPolicy () {}
WidgetURIPolicy.prototype = {
    classDescription:   "Implements content policy to prevent cross widget access",
    classID:            Components.ID("{ff795b25-dad0-43c5-9da2-7ffe3a6343f8}"),
    contractID:         "@desre.org/widget-uri-policy;1",
    _xpcom_categories:  [{ category: "content-policy"}],
    QueryInterface:     XPCOMUtils.generateQI([Ci.nsIContentPolicy]),
    
    shouldLoad: function (contType, contLoc, reqOrig, ctx, typeGuess, extra) {
        if (contLoc.scheme == "widget" && reqOrig && reqOrig.scheme == "widget") {
            if (contLoc.host == reqOrig.host) return Ci.nsIContentPolicy.ACCEPT;
            else                              return Ci.nsIContentPolicy.REJECT_OTHER; // maybe use REJECT_SERVER ?
        }
        return Ci.nsIContentPolicy.ACCEPT;
    },
    
    shouldProcess: function (contType, contLoc, reqOrig, ctx, mimeType, extra) {
        return Ci.nsIContentPolicy.ACCEPT;
    }
};

xpcom.register({
    create:     WidgetURIPolicy,
    name:       WidgetURIPolicy.prototype.classDescription,
    contractID: WidgetURIPolicy.prototype.contractID,
    uuid:       WidgetURIPolicy.prototype.classID
});
